<?php

use Core\ResourceController;
use Models\Ad;
use Models\Category;
use Models\Product;

class SiteController extends ResourceController
{
	public function index()
	{
		$ad = new Ad;
		$ads = $ad->where_in('type',array('INDEX_1','INDEX_2','INDEX_3'))->get();

		$data['ads'] = [];
		$data['brands'] = [];
		$data['ad'] = [];
		foreach ($ads as $key => $value) {
			if ($value['type'] == 'INDEX_1') {
				$data['ads'][] = $value;
			} else if ($value['type'] == 'INDEX_2') {
				$data['brands'][] = $value;
			} else if ($value['type'] == 'INDEX_3') {
				$data['ad'] = $value;
			}
		}

		$category = new Category;
		$data['categories'] = $category->where('parent_id',0)->order_by('sort','desc')->get();
		$product = new Product;
		$data['products'] = $product->select('id,title,thumbnail,price,original_price')->where('is_hot',1)->where('status',1)->order_by('sort','desc')->limit(10)->get();

		return $this->success($data);
	}

	public function getHots($page = 1)
	{
		$product = new Product;
		$data = $product->select('id,title,thumbnail,price,original_price')->where('is_hot',1)->where('status',1)->order_by('sort','desc')->limit(10)->offset(($page-1)*10)->get();

		return $this->success($data);
	}
}
